/**
 * @author LKQ
 * @date 2022/1/7 10:40
 * @description 贪心，维护最远距离
 */
public class Solution {
    public static void main(String[] args) {

    }
    public boolean canJump(int[] nums) {
        int n = nums.length;
        int rightmost = 0;
        for (int i = 0; i < n; ++i) {
            if (i <= rightmost) {
                // x位置能跳到的最远位置位 x+nums[i]，更新最远即可
                rightmost = Math.max(rightmost, i + nums[i]);
                if (rightmost >= n - 1) {
                    return true;
                }
            }
        }
        return false;
    }
}
